package com.tesco.utils;

import cn.hutool.core.net.multipart.UploadFile;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tesco.dao.FileDao;
import com.tesco.entity.domin.ServiceFile;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @Author:jc
 * @Date:2022/1/25 15:36
 * @Description:com.tesco.utils
 */
@Component
public class FileHelper {

    private static  FileDao fileDao;

    @Resource
    private FileDao file;

    @PostConstruct
    public void setFileDao(){
        fileDao = file;
    }


    public  static List<String> randomPicture(String pictureType){
        QueryWrapper<ServiceFile> wrapper = new QueryWrapper<>();
        wrapper.like(ServiceFile.COL_FILEORIGINALNAME,pictureType);
        List<ServiceFile> uploadFiles = fileDao.selectList(wrapper);
        List<String> strings = new ArrayList<>();
        if (uploadFiles.size()>0){
            for (ServiceFile uploadFile : uploadFiles) {
                strings.add("www.superhack.top:12345/file/"+uploadFile.getFilename().substring(0,8)+"/"+uploadFile.getFilename());
            }
        }

        return strings;
    }

}
